package cn.mhome.merchant.dao.jpa.business;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import cn.mhome.merchant.dao.common.po.Business;

public interface BusinessDao extends JpaRepository<Business,Long>,BusinessDaoCustom{

	@Query("SELECT COUNT(*) FROM Business WHERE businessId <>:businessId and city =:city and businessName =:businessName")
	Long findSameCount(@Param("businessId") long businessId,@Param("city") String city,@Param("businessName") String businessName);

	@Query("SELECT COUNT(*) FROM Business WHERE city =:city and businessName =:businessName")
	Long findSameCount(@Param("city")String city, @Param("businessName")String businessName);

	@Modifying
	@Query("UPDATE Business SET visitCount = visitCount + 1 WHERE businessId =:businessId")
	void updateVisteCount(@Param("businessId") long businessId);
	
	@Modifying
	@Query("UPDATE Business SET contactCount = contactCount + 1 WHERE businessId =:businessId")
	void updateContactCount(@Param("businessId") long businessId);

}
